package day20210128;

import org.junit.Test;

public class LookAndSaySequence {

    public String test01(int n) {
        if (n==1) {
            return "1";
        }
        String str = test01(n-1);
        StringBuilder stringBuilder = new StringBuilder();
        int start = 0 ,len = str.length();
        for (int i = 1 ; i < len+1 ; i++ ) {
            if (i==len) {
                stringBuilder.append(i-start).append(str.charAt(start));
            }else if (str.charAt(i) != str.charAt(start)) {
                stringBuilder.append(i-start).append(str.charAt(start));
                start = i;
            }
        }
        return stringBuilder.toString();
    }

    @Test
    public void test01() {
        String s = test01(4);
        System.out.println(s);
    }
}
